ABC137 C - Green Bin
https://atcoder.jp/contests/abc137/tasks/abc137_c
提出
code: python
n = int(input())
s = input() for _ in range(n)
strings = set()
anagrams = {}
for i in s:
sortedString = ''.join(sorted(i))
if (sortedString in strings):
try:
anagramssortedString += 1
except KeyError:
anagramssortedString = 1
else:
strings.add(sortedString)
ans = 0
for i in anagrams.values():
ans += (i * (i+1)) // 2
print(ans)
メモ
TLE
code: python
n = int(input())
s = input() for _ in range(n)
sortedS = []
for i in s:
sortedS.append(''.join(sorted(i)))
setS = set(sortedS)
ans = 0
for i in setS:
anagramCounts = sortedS.count(i)
ans += (anagramCounts * (anagramCounts - 1)) // 2
print(ans)